<template>
  <div class="test">
    <div>
      <p>{{ msg }}</p>
      <button @click="mockTest">get模拟数据</button>
    </div>
  </div>
</template>

<script>
import Mock from "mockjs";
export default {
  name: "test",
  data() {
    return {
      msg: "mockjs模拟前后台交互",
    };
  },
  methods: {
    mockTest() {
      Mock.mock("http://mockjs/test", {
        userName: "@cname",
      });
      this.$axios
        .get("http://mockjs/test")
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped></style>
